import storageApi from '../../../core/storage/storage';

function checkMonthController($rootScope, $scope, homeStatsService, staffService) {
  'ngInject';

  /*eslint-disable */
  // 巡查统计
  this.initCheckMonth = () => {
    this.xAxisData = [];
    this.yAxisData = [];
    homeStatsService
      .getMonthCheck({ orgId : $rootScope.orgId || storageApi.get('orgId') })
      .then((res) => {
        if (res.success) {
          res.rows.forEach((item) => {
            this.xAxisData.push(item.name);
            this.yAxisData.push(item.total);
            this.initCharts(this.xAxisData, this.yAxisData);
          })

        }
      });
  };

  this.initCharts = (xAxisData, yAxisData) => {
    const option3 = {
      tooltip : {
        trigger: 'axis',
        axisPointer : {
          type : 'shadow'
        }
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis : [
        {
          type : 'category',
          data : xAxisData
        }
      ],
      yAxis : [
        {
          type : 'value'
        }
      ],
      series : [
        {
          name:'',
          type:'bar',
          data: yAxisData
        },
      ]
    };
    const myChart = echarts.init(document.getElementById('check-total'));
    myChart.setOption(option3);
  };

  this.initCheckMonth();
}

export default checkMonthController;
